//
//  YFNetError.m
//  SquashSpark
//
//  Created by Coollang on 2017/11/4.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "YFNetError.h"
#import "JCError.h"

@implementation YFNetError

+ (YFNetError *)creatErrorWithRet:(WebRespondType)ret {
    YFNetError *error;
    switch (ret) {
        case WebRespondTypeArgumentInexist://参数不存在
            error = (YFNetError *)[YFNetError errorWithDomain:@"Parameter does not exist" code:WebRespondTypeArgumentInexist];
            break;
        case WebRespondTypeArgumentError://参数错误！
            error = (YFNetError *)[YFNetError errorWithDomain:@"Parameter mistake" code:WebRespondTypeArgumentError];
            break;
        case WebRespondTypeGetDataFail://系统错误
            error = (YFNetError *)[YFNetError errorWithDomain:@"System mistake" code:WebRespondTypeGetDataFail];
            break;
        case WebRespondTypeTokenInexist://token不存在
            error = (YFNetError *)[YFNetError errorWithDomain:@"token does not exist" code:WebRespondTypeTokenInexist];
            break;
        case WebRespondTypeTokenInconformity://签名不一致
            error = (YFNetError *)[YFNetError errorWithDomain:@"Signature inconformity" code:WebRespondTypeTokenInconformity];
            break;
        case WebRespondTypeRequestFaild://接口请求失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Failed to get data" code:WebRespondTypeRequestFaild];
            break;
        case WebRespondTypeNotReachable://网络未连接
            error = (YFNetError *)[YFNetError errorWithDomain:@"Network disconnected" code:WebRespondTypeNotReachable];
            break;
        case WebRespondTypeATimeOut://请求超时
            error = [YFNetError errorWithDomain:@"Request timed out" code:WebRespondTypeATimeOut];
            break;
        case WebRespondTypeEmailInvalid://email参数错误
            error = (YFNetError *)[YFNetError errorWithDomain:@"Parameter mistake" code:WebRespondTypeEmailInvalid];
            break;
        case WebRespondTypePasswordInvalid://密码格式不正确:登录用MD5
            error = (YFNetError *)[YFNetError errorWithDomain:@"Incorrect password format,login with MD5" code:WebRespondTypePasswordInvalid];
            break;
        case WebRespondTypeUserExit://该用户已存在
            error = (YFNetError *)[YFNetError errorWithDomain:@"User already exists" code:WebRespondTypeUserExit];
            break;
        case WebRespondTypeLRegistFail://注册失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Registration failed" code:WebRespondTypeLRegistFail];
            break;
        case WebRespondTypeNoUser://该用户不存在
            error = (YFNetError *)[YFNetError errorWithDomain:@"User does not exist" code:WebRespondTypeNoUser];
            break;
        case WebRespondTypeAccountOrPasswordEoor:// 帐号密码错误
            error = (YFNetError *)[YFNetError errorWithDomain:@"Your email or password was entered incorrectly" code:WebRespondTypeAccountOrPasswordEoor];
            break;
        case WebRespondTypeNotLogin://登录失效
            error = (YFNetError *)[YFNetError errorWithDomain:@"Login invalid" code:WebRespondTypeNotLogin];
            break;
        case WebRespondTypeSaveUserInfoFaild://保存个人信息失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Failed to save personal info." code:WebRespondTypeSaveUserInfoFaild];
            break;
        case WebRespondTypeChangePasswordFaild://修改密码失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Failed to change password" code:WebRespondTypeChangePasswordFaild];
            break;
        case  WebRespondTypeResetPasswordFrequently:
            //发送找回密码过于频繁,请1分钟后再来
            error = (YFNetError *)[YFNetError errorWithDomain:@"One minute can only send an E-mail" code:WebRespondTypeResetPasswordFrequently];
            break;
        case WebRespondTypeTopicNotexit:
            error = (YFNetError *)[YFNetError errorWithDomain:@"Post does not exist" code:WebRespondTypeTopicNotexit];
            break;
        case WebRespondTypeCommentNotexit:
            error = (YFNetError *)[YFNetError errorWithDomain:@"Original comment does not exist" code:WebRespondTypeCommentNotexit];
            break;
            //俱乐部错误码
        case WebRespondTypeClubCodeInvalid:
            error = (YFNetError *)[YFNetError errorWithDomain:@"Invalid verification code" code:WebRespondTypeClubCodeInvalid];
            break;
        case WebRespondTypeClubCodeWasUsed:// 验证码已被使用
            error = (YFNetError *)[YFNetError errorWithDomain:@"Verification code has been used" code:WebRespondTypeClubCodeWasUsed];
            break;
        case WebRespondTypeClubCreatClubFaild:// 创建俱乐部失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Failed to create the club" code:WebRespondTypeClubCreatClubFaild];
            break;
        case WebRespondTypeClubCreatEventFaild:// 创建消息失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Failed to create emessage" code:WebRespondTypeClubCreatEventFaild];
            break;
        case WebRespondTypeClubNotExist:// 该俱乐部不存在
            error = (YFNetError *)[YFNetError errorWithDomain:@"Club does not exist" code:WebRespondTypeClubNotExist];
            break;
        case WebRespondTypeClubNotAllowed:// 非法操作，暂无权限
            error = (YFNetError *)[YFNetError errorWithDomain:@"illegal operation, no permission" code:WebRespondTypeClubNotAllowed];
            break;
        case WebRespondTypeClubSetTargetFaild:// 设置俱乐部目标失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Failed to set the club goals" code:WebRespondTypeClubSetTargetFaild];
            break;
        case WebRespondTypeClubNotRepeatJoin:// 你已是该俱乐部成员
            error = (YFNetError *)[YFNetError errorWithDomain:@"You are the member of this club" code:WebRespondTypeClubNotRepeatJoin];
            break;
        case WebRespondTypeClubNoReport:// 你还没有周报
            error = (YFNetError *)[YFNetError errorWithDomain:NSLocalizedString(@"You don't have weekly report yet", @"你还没有周报") code:WebRespondTypeClubNoReport];
            break;
        case WebRespondTypeClubNoThisMember:// 俱乐部中不存在该成员!
            error = (YFNetError *)[YFNetError errorWithDomain:@"The Member Does Not Exist In The Club" code:WebRespondTypeClubNoThisMember];
            break;
        case wWeRespondTypeUploadDetailDataFail:// 详情数据上传失败!
            error = (YFNetError *)[YFNetError errorWithDomain:@"Detail Data Upload Failed" code:wWeRespondTypeUploadDetailDataFail];
            break;
        case WebRespondTypeJoinClubPasswordError:// 加入俱乐部密码错误
            error = (YFNetError *)[YFNetError errorWithDomain:@"Wrong Password To Join The Club" code:WebRespondTypeJoinClubPasswordError];
            break;
        case WebRespondTypeClubSetPassFaild:// 密码设置失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Password Failure" code:WebRespondTypeClubSetPassFaild];
            break;
        case WebRespondTypeClubYouHaveCommentReport:// 您已经评论过该成员的周报了!
            error = (YFNetError *)[YFNetError errorWithDomain:@"You Have Already Commented On This Member's Weekly Report." code:WebRespondTypeClubYouHaveCommentReport];
            break;
        case WebRespondTypeClubCoachCommentFaild://练评论失败!
            error = (YFNetError *)[YFNetError errorWithDomain:@"Coach Comments Failed" code:WebRespondTypeClubCoachCommentFaild];
            break;
        case WebRespondTypeClubNotFinishTarget:// 该成员该周没有完成计划!
            error = (YFNetError *)[YFNetError errorWithDomain:@"The Member Didn't Complete The Plan This Week" code:WebRespondTypeClubNotFinishTarget];
            break;
        case WebRespondTypeClubJoinClubFaild://加入俱乐部失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Failed To Join In Club" code:WebRespondTypeClubJoinClubFaild];
            break;
        case WebRespondTypeClubNotRepeatJoin2:// 您已经加入了该俱乐部
            error = (YFNetError *)[YFNetError errorWithDomain:@"Successfully Joined The Club" code:WebRespondTypeClubNotRepeatJoin2];
            break;
        case WebRespondTypeClubQuitClubFaild:// 退出失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Exit Failed" code:WebRespondTypeClubQuitClubFaild];
            break;
        case WebRespondTypeClubEditFaild:// 修改失败
            error = (YFNetError *)[YFNetError errorWithDomain:@"Failed To Edit" code:WebRespondTypeClubEditFaild];
            break;
        case WebRespondTypeGetFirmwareFaild:// 获取固件版本失败！
            error = (YFNetError *)[YFNetError errorWithDomain:@"Failed To Get Firmware Version" code:WebRespondTypeGetFirmwareFaild];
            break;
        case WebRespondTypeServiceError:
        case WebRespondTypeServiceError404:// 服务器出错
            error = (YFNetError *)[YFNetError errorWithDomain:[NSString stringWithFormat:@"Server Error-%ld!",(long)ret] code:WebRespondTypeServiceError];
            break;
        default:// 未知错误
            error = (YFNetError *)[YFNetError errorWithDomain:@"Unknown Mistake" code:WebRespondTypeGetDataFail];
            break;
    }
    return error;
}

+ (WebRespondType)WebRespondTypeWithRet:(NSString *)retStr {
    if (retStr.length <= 0) {
        return WebRespondTypeOther;
    }
    NSInteger ret = [retStr integerValue];
    return ret;
}

@end


